package com.echat.config.security.service.impl;

import com.echat.business.home.model.SysUser;
import com.echat.business.home.service.ISysUserService;
import com.echat.config.security.service.MyUserDetailsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;

import java.util.Collections;

/**
 * @author fengbo
 */
@Service
@Slf4j
public class MyUserDetailsServiceImpl implements MyUserDetailsService {

    @Autowired
    private ISysUserService userService;

    @Override
    public UserDetails loadUserByUsername(String username) {
        log.info("登录用户名:" + username);
        //User三个参数   (用户名+密码+权限)
        SysUser sysUser = userService.getUserByName(username);
        String password = "";
        if (sysUser != null) {
            password = sysUser.getPassword();
            log.info("数据库中的用户密码: " + password);
        }
        return new User(username, password,
                true, true, true, true,
                Collections.EMPTY_SET);
    }

}

